package io.jt808.proto.req;

import io.norland.buffer.AutoBuffer;
import io.norland.annotations.Proto;
import io.norland.proto.IProto;
import lombok.Data;

/**
 * 数据压缩上报
 */
@Proto("0901")
@Data
public class JT0901 implements IProto {
    /**
     * 压缩消息长度
     */
    private int messageLength;
    /**
     * 压缩消息体为需要压缩的消息经过 GZIP 压缩算法
     * 后的消息
     */
    private byte[] messageContent;

    public final byte[] writeToBytes() {
        AutoBuffer buffer = new AutoBuffer();
        buffer.writeInt(messageLength);
        buffer.writeBytes(messageContent);
        return buffer.array();
    }

    public final void readFromBuf(AutoBuffer buffer) {
        messageLength = buffer.readInt();
        messageContent = buffer.readBytes();
    }
}